﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references
namespace TierApplication
{
	/// <summary>
	/// 类T_PRODUCTITEM。
	/// </summary>
	[Serializable]
    public partial class T_PRODUCTITEM
    {
        public T_PRODUCTITEM()
        { }
        #region Model
        private string _productitemid;
        private string _cardno;
        private string _cardpwd;
        private string _productitemstatus;
        private DateTime? _usefullife;
        private string _impbatchno;
        private string _productid;
        private string _remark;
        private string _lastlockaccountid;
        private DateTime? _lastlocktime;
        private string _lastalteruserid;
        private DateTime? _lastaltertime;
        /// <summary>
        /// 商品条目编号
        /// </summary>
        public string PRODUCTITEMID
        {
            set { _productitemid = value; }
            get { return _productitemid; }
        }
        /// <summary>
        /// 充值卡卡号
        /// </summary>
        public string CARDNO
        {
            set { _cardno = value; }
            get { return _cardno; }
        }
        /// <summary>
        /// 充值卡密码
        /// </summary>
        public string CARDPWD
        {
            set { _cardpwd = value; }
            get { return _cardpwd; }
        }
        /// <summary>
        /// 状态 0 未审核（C_ProductItemStatus数据导入初始状态，审核后状态变为待售）1待售2 生成订单未付款3 已付款

        /// </summary>
        public string PRODUCTITEMSTATUS
        {
            set { _productitemstatus = value; }
            get { return _productitemstatus; }
        }
        /// <summary>
        /// 有效期
        /// </summary>
        public DateTime? USEFULLIFE
        {
            set { _usefullife = value; }
            get { return _usefullife; }
        }
        /// <summary>
        /// 导入批号(数据导入时生成的流水号)
        /// </summary>
        public string IMPBATCHNO
        {
            set { _impbatchno = value; }
            get { return _impbatchno; }
        }
        /// <summary>
        /// 商品编号
        /// </summary>
        public string PRODUCTID
        {
            set { _productid = value; }
            get { return _productid; }
        }
        /// <summary>
        /// 备注
        /// </summary>
        public string REMARK
        {
            set { _remark = value; }
            get { return _remark; }
        }
        /// <summary>
        /// 最后选择人(T_Account)
        /// </summary>
        public string LASTLOCKACCOUNTID
        {
            set { _lastlockaccountid = value; }
            get { return _lastlockaccountid; }
        }
        /// <summary>
        /// 最后操作时间SysTimeStamp
        /// </summary>
        public DateTime? LASTLOCKTIME
        {
            set { _lastlocktime = value; }
            get { return _lastlocktime; }
        }
        /// <summary>
        /// 最后修改人（后台修改）
        /// </summary>
        public string LASTALTERUSERID
        {
            set { _lastalteruserid = value; }
            get { return _lastalteruserid; }
        }
        /// <summary>
        /// 最后修改时间（后台修改）
        /// </summary>
        public DateTime? LASTALTERTIME
        {
            set { _lastaltertime = value; }
            get { return _lastaltertime; }
        }
        #endregion Model


        #region  Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public T_PRODUCTITEM(string PRODUCTITEMID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select PRODUCTITEMID,CARDNO,CARDPWD,PRODUCTITEMSTATUS,USEFULLIFE,IMPBATCHNO,PRODUCTID,REMARK,LASTLOCKACCOUNTID,LASTLOCKTIME,LASTALTERUSERID,LASTALTERTIME ");
            strSql.Append(" FROM T_PRODUCTITEM ");
            strSql.Append(" where PRODUCTITEMID=:PRODUCTITEMID ");
            OracleParameter[] parameters = {
					new OracleParameter(":PRODUCTITEMID", OracleType.VarChar,50)};
            parameters[0].Value = PRODUCTITEMID;

            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["PRODUCTITEMID"] != null && ds.Tables[0].Rows[0]["PRODUCTITEMID"].ToString() != "")
                {
                    this.PRODUCTITEMID = ds.Tables[0].Rows[0]["PRODUCTITEMID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CARDNO"] != null && ds.Tables[0].Rows[0]["CARDNO"].ToString() != "")
                {
                    this.CARDNO = ds.Tables[0].Rows[0]["CARDNO"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CARDPWD"] != null && ds.Tables[0].Rows[0]["CARDPWD"].ToString() != "")
                {
                    this.CARDPWD = ds.Tables[0].Rows[0]["CARDPWD"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PRODUCTITEMSTATUS"] != null && ds.Tables[0].Rows[0]["PRODUCTITEMSTATUS"].ToString() != "")
                {
                    this.PRODUCTITEMSTATUS = ds.Tables[0].Rows[0]["PRODUCTITEMSTATUS"].ToString();
                }
                if (ds.Tables[0].Rows[0]["USEFULLIFE"] != null && ds.Tables[0].Rows[0]["USEFULLIFE"].ToString() != "")
                {
                    this.USEFULLIFE = DateTime.Parse(ds.Tables[0].Rows[0]["USEFULLIFE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IMPBATCHNO"] != null && ds.Tables[0].Rows[0]["IMPBATCHNO"].ToString() != "")
                {
                    this.IMPBATCHNO = ds.Tables[0].Rows[0]["IMPBATCHNO"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PRODUCTID"] != null && ds.Tables[0].Rows[0]["PRODUCTID"].ToString() != "")
                {
                    this.PRODUCTID = ds.Tables[0].Rows[0]["PRODUCTID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["REMARK"] != null && ds.Tables[0].Rows[0]["REMARK"].ToString() != "")
                {
                    this.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LASTLOCKACCOUNTID"] != null && ds.Tables[0].Rows[0]["LASTLOCKACCOUNTID"].ToString() != "")
                {
                    this.LASTLOCKACCOUNTID = ds.Tables[0].Rows[0]["LASTLOCKACCOUNTID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LASTLOCKTIME"] != null && ds.Tables[0].Rows[0]["LASTLOCKTIME"].ToString() != "")
                {
                    this.LASTLOCKTIME = DateTime.Parse(ds.Tables[0].Rows[0]["LASTLOCKTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LASTALTERUSERID"] != null && ds.Tables[0].Rows[0]["LASTALTERUSERID"].ToString() != "")
                {
                    this.LASTALTERUSERID = ds.Tables[0].Rows[0]["LASTALTERUSERID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LASTALTERTIME"] != null && ds.Tables[0].Rows[0]["LASTALTERTIME"].ToString() != "")
                {
                    this.LASTALTERTIME = DateTime.Parse(ds.Tables[0].Rows[0]["LASTALTERTIME"].ToString());
                }
            }
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string PRODUCTITEMID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_PRODUCTITEM");
            strSql.Append(" where PRODUCTITEMID=:PRODUCTITEMID ");

            OracleParameter[] parameters = {
					new OracleParameter(":PRODUCTITEMID", OracleType.VarChar,50)};
            parameters[0].Value = PRODUCTITEMID;

            return DbHelperOra.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_PRODUCTITEM (");
            strSql.Append("PRODUCTITEMID,CARDNO,CARDPWD,PRODUCTITEMSTATUS,USEFULLIFE,IMPBATCHNO,PRODUCTID,REMARK,LASTLOCKACCOUNTID,LASTLOCKTIME,LASTALTERUSERID,LASTALTERTIME)");
            strSql.Append(" values (");
            strSql.Append(":PRODUCTITEMID,:CARDNO,:CARDPWD,:PRODUCTITEMSTATUS,:USEFULLIFE,:IMPBATCHNO,:PRODUCTID,:REMARK,:LASTLOCKACCOUNTID,:LASTLOCKTIME,:LASTALTERUSERID,:LASTALTERTIME)");
            OracleParameter[] parameters = {
					new OracleParameter(":PRODUCTITEMID", OracleType.VarChar,20),
					new OracleParameter(":CARDNO", OracleType.VarChar,30),
					new OracleParameter(":CARDPWD", OracleType.VarChar,90),
					new OracleParameter(":PRODUCTITEMSTATUS", OracleType.VarChar,1),
					new OracleParameter(":USEFULLIFE", OracleType.DateTime),
					new OracleParameter(":IMPBATCHNO", OracleType.VarChar,20),
					new OracleParameter(":PRODUCTID", OracleType.VarChar,20),
					new OracleParameter(":REMARK", OracleType.VarChar,200),
					new OracleParameter(":LASTLOCKACCOUNTID", OracleType.VarChar,20),
					new OracleParameter(":LASTLOCKTIME", OracleType.DateTime),
					new OracleParameter(":LASTALTERUSERID", OracleType.VarChar,20),
					new OracleParameter(":LASTALTERTIME", OracleType.DateTime)};
            parameters[0].Value = PRODUCTITEMID;
            parameters[1].Value = CARDNO;
            parameters[2].Value = CARDPWD;
            parameters[3].Value = PRODUCTITEMSTATUS;
            parameters[4].Value = USEFULLIFE;
            parameters[5].Value = IMPBATCHNO;
            parameters[6].Value = PRODUCTID;
            parameters[7].Value = REMARK;
            parameters[8].Value = LASTLOCKACCOUNTID;
            parameters[9].Value = LASTLOCKTIME;
            parameters[10].Value = LASTALTERUSERID;
            parameters[11].Value = LASTALTERTIME;

            DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_PRODUCTITEM set ");
            strSql.Append("CARDNO=:CARDNO,");
            strSql.Append("CARDPWD=:CARDPWD,");
            strSql.Append("PRODUCTITEMSTATUS=:PRODUCTITEMSTATUS,");
            strSql.Append("USEFULLIFE=:USEFULLIFE,");
            strSql.Append("IMPBATCHNO=:IMPBATCHNO,");
            strSql.Append("PRODUCTID=:PRODUCTID,");
            strSql.Append("REMARK=:REMARK,");
            strSql.Append("LASTLOCKACCOUNTID=:LASTLOCKACCOUNTID,");
            strSql.Append("LASTLOCKTIME=:LASTLOCKTIME,");
            strSql.Append("LASTALTERUSERID=:LASTALTERUSERID,");
            strSql.Append("LASTALTERTIME=:LASTALTERTIME");
            strSql.Append(" where PRODUCTITEMID=:PRODUCTITEMID ");
            OracleParameter[] parameters = {
					new OracleParameter(":CARDNO", OracleType.VarChar,30),
					new OracleParameter(":CARDPWD", OracleType.VarChar,90),
					new OracleParameter(":PRODUCTITEMSTATUS", OracleType.VarChar,1),
					new OracleParameter(":USEFULLIFE", OracleType.DateTime),
					new OracleParameter(":IMPBATCHNO", OracleType.VarChar,20),
					new OracleParameter(":PRODUCTID", OracleType.VarChar,20),
					new OracleParameter(":REMARK", OracleType.VarChar,200),
					new OracleParameter(":LASTLOCKACCOUNTID", OracleType.VarChar,20),
					new OracleParameter(":LASTLOCKTIME", OracleType.DateTime),
					new OracleParameter(":LASTALTERUSERID", OracleType.VarChar,20),
					new OracleParameter(":LASTALTERTIME", OracleType.DateTime),
					new OracleParameter(":PRODUCTITEMID", OracleType.VarChar,20)};
            parameters[0].Value = CARDNO;
            parameters[1].Value = CARDPWD;
            parameters[2].Value = PRODUCTITEMSTATUS;
            parameters[3].Value = USEFULLIFE;
            parameters[4].Value = IMPBATCHNO;
            parameters[5].Value = PRODUCTID;
            parameters[6].Value = REMARK;
            parameters[7].Value = LASTLOCKACCOUNTID;
            parameters[8].Value = LASTLOCKTIME;
            parameters[9].Value = LASTALTERUSERID;
            parameters[10].Value = LASTALTERTIME;
            parameters[11].Value = PRODUCTITEMID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string PRODUCTITEMID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_PRODUCTITEM ");
            strSql.Append(" where PRODUCTITEMID=:PRODUCTITEMID ");
            OracleParameter[] parameters = {
					new OracleParameter(":PRODUCTITEMID", OracleType.VarChar,50)};
            parameters[0].Value = PRODUCTITEMID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(string PRODUCTITEMID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select PRODUCTITEMID,CARDNO,CARDPWD,PRODUCTITEMSTATUS,USEFULLIFE,IMPBATCHNO,PRODUCTID,REMARK,LASTLOCKACCOUNTID,LASTLOCKTIME,LASTALTERUSERID,LASTALTERTIME ");
            strSql.Append(" FROM T_PRODUCTITEM ");
            strSql.Append(" where PRODUCTITEMID=:PRODUCTITEMID ");
            OracleParameter[] parameters = {
					new OracleParameter(":PRODUCTITEMID", OracleType.VarChar,50)};
            parameters[0].Value = PRODUCTITEMID;

            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["PRODUCTITEMID"] != null && ds.Tables[0].Rows[0]["PRODUCTITEMID"].ToString() != "")
                {
                    this.PRODUCTITEMID = ds.Tables[0].Rows[0]["PRODUCTITEMID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CARDNO"] != null && ds.Tables[0].Rows[0]["CARDNO"].ToString() != "")
                {
                    this.CARDNO = ds.Tables[0].Rows[0]["CARDNO"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CARDPWD"] != null && ds.Tables[0].Rows[0]["CARDPWD"].ToString() != "")
                {
                    this.CARDPWD = ds.Tables[0].Rows[0]["CARDPWD"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PRODUCTITEMSTATUS"] != null && ds.Tables[0].Rows[0]["PRODUCTITEMSTATUS"].ToString() != "")
                {
                    this.PRODUCTITEMSTATUS = ds.Tables[0].Rows[0]["PRODUCTITEMSTATUS"].ToString();
                }
                if (ds.Tables[0].Rows[0]["USEFULLIFE"] != null && ds.Tables[0].Rows[0]["USEFULLIFE"].ToString() != "")
                {
                    this.USEFULLIFE = DateTime.Parse(ds.Tables[0].Rows[0]["USEFULLIFE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IMPBATCHNO"] != null && ds.Tables[0].Rows[0]["IMPBATCHNO"].ToString() != "")
                {
                    this.IMPBATCHNO = ds.Tables[0].Rows[0]["IMPBATCHNO"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PRODUCTID"] != null && ds.Tables[0].Rows[0]["PRODUCTID"].ToString() != "")
                {
                    this.PRODUCTID = ds.Tables[0].Rows[0]["PRODUCTID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["REMARK"] != null && ds.Tables[0].Rows[0]["REMARK"].ToString() != "")
                {
                    this.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LASTLOCKACCOUNTID"] != null && ds.Tables[0].Rows[0]["LASTLOCKACCOUNTID"].ToString() != "")
                {
                    this.LASTLOCKACCOUNTID = ds.Tables[0].Rows[0]["LASTLOCKACCOUNTID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LASTLOCKTIME"] != null && ds.Tables[0].Rows[0]["LASTLOCKTIME"].ToString() != "")
                {
                    this.LASTLOCKTIME = DateTime.Parse(ds.Tables[0].Rows[0]["LASTLOCKTIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LASTALTERUSERID"] != null && ds.Tables[0].Rows[0]["LASTALTERUSERID"].ToString() != "")
                {
                    this.LASTALTERUSERID = ds.Tables[0].Rows[0]["LASTALTERUSERID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LASTALTERTIME"] != null && ds.Tables[0].Rows[0]["LASTALTERTIME"].ToString() != "")
                {
                    this.LASTALTERTIME = DateTime.Parse(ds.Tables[0].Rows[0]["LASTALTERTIME"].ToString());
                }
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM T_PRODUCTITEM ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }

        #endregion  Method
    }
}

